import { formatNum } from '@/utils/utils'
import { get } from './index'

function formatData(surveys) {
  surveys.forEach(sur => {
    const d = new Date(Number.parseInt(sur.create_time))
    sur.time_format =
      d.getFullYear() +
      '年' +
      formatNum(d.getMonth() + 1) +
      '月' +
      formatNum(d.getDate()) +
      '日' +
      ' ' +
      formatNum(d.getHours()) +
      ':' +
      formatNum(d.getMinutes())
  })
  surveys.sort((a, b) => b.create_time - a.create_time)
  return surveys
}

export default function () {
  return new Promise(async res => {
    let delSurvey = undefined
    try {
      const { data } = await get('/admin/survey/deleted')
      console.log('debugger: ', data)
      if (data.msg === 'success') {
        delSurvey = formatData(data.data)
      } else console.warn(data.msg)
    } catch (error) {
      console.error(error.message)
    }
    res(delSurvey)
  })
}
